import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { viteCommonjs } from '@originjs/vite-plugin-commonjs'
import { resolve } from 'path'

const pathResolve = (dir) => {
  return resolve(__dirname, '.', dir)
}

import * as path from 'path'

export default defineConfig(({ mode }) => {
  const name = 'flowlong-designer'
  if (mode === 'lib') {
    return {
      plugins: [vue(), viteCommonjs()],
      resolve: {
        alias: {
          '@': pathResolve('src')
        }
      },
      base: './',
      publicDir: 'public',
      build: {
        lib: {
          name,
          fileName: name,
          entry: path.resolve(__dirname, 'src/main.js')
          // formats: ['es', 'cjs']
        },
        rollupOptions: {
          output: {
            inlineDynamicImports: true,
            sourcemap: true
          }
        }
      }
    }
  }
  return {
    plugins: [vue(), viteCommonjs()],
    resolve: {
      alias: {
        '@': pathResolve('src')
      }
    },
    base: './',
    publicDir: 'public',
    build: {
      minify: 'terser',
      terserOptions: {
        compress: {
          drop_console: true,
          drop_debugger: true
        }
      }
    },
    server: {
      host: '0.0.0.0'
    }
  }
})

